class Solution
{
public:
    int maxLengthBetweenEqualCharacters(string s)
    {
        vector<int> fisrtOccur(26, -1);
        int maxInterval = -1;
        int n = s.size();
        for (int i = 0; i < n; ++i)
        {
            if (fisrtOccur[s[i] - 'a'] == -1)
            {
                fisrtOccur[s[i] - 'a'] = i;
            }
            else
            {
                int interval = i - fisrtOccur[s[i] - 'a'] - 1;
                maxInterval = max(maxInterval, interval);
            }
        }
        return maxInterval;
    }
};